home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Online / opennap / list.h < prev    next >
C/C++ Source or Header  |  2001-06-08  |  1KB  |  55 lines

  1. /* Copyright (C) 2000 drscholl@users.sourceforge.net
  2.    This is free software distributed under the terms of the
  3.    GNU Public License.  See the file COPYING for details.
  4.  
  5.    $Id: list.h,v 1.8 2000/12/27 09:51:19 drscholl Exp $ */
  6.  
  7. #ifndef list_h
  8. #define list_h
  9.  
  10. typedef struct list LIST;
  11.  
  12. struct list {
  13.     void *data;
  14.     LIST *next;
  15. };
  16.  
  17. /* prototype for list_free() callback function */
  18. typedef void (*list_destroy_t) (void *);
  19.  
  20. typedef void (*list_callback_t) (void *, void *);
  21.  
  22. /* create a new list struct with the given data */
  23. LIST *list_new (void *);
  24.  
  25. /* removes the specified element from the list */
  26. LIST *list_delete (LIST *, void *);
  27.  
  28. /* append an element to the list */
  29. LIST *list_append (LIST *, LIST *);
  30.  
  31. LIST *list_append_data (LIST *, void *);
  32.  
  33. /* add element to beginning of list */
  34. LIST *list_push (LIST *, LIST *);
  35.  
  36. /* free a list element */
  37. void list_free (LIST *, list_destroy_t);
  38.  
  39. /* return the number of items in a list */
  40. int list_count (LIST *);
  41.  
  42. LIST *list_find (LIST *, void *);
  43.  
  44. int list_validate (LIST *);
  45.  
  46. void list_foreach (LIST *, list_callback_t, void *);
  47.  
  48. #if DEBUG
  49. #define LIST_NEW(p,d) { p = CALLOC (1, sizeof (LIST)); if (p) (p)->data = d; }
  50. #else
  51. #define LIST_NEW(p,d) p = list_new (d)
  52. #endif /* DEBUG */
  53.  
  54. #endif /* list_h */
  55.